﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;

namespace RecordBeRun
{
    public partial class UserAddFrom : Form
    {
        public Mode StartMode { get; set; }
        public UserAddFrom()
        {
            InitializeComponent();
            combx_Mentor.DataSource = Program.UserViewModelLocator.AllMentors;
        }
        
        private void btn_User_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txb_MentorName.Text.Trim()))
            {
                MessageBox.Show("请输入姓名","提示", MessageBoxButtons.OK);
                return;
            }
            switch (tab_AddUser.SelectedIndex)
            {
                case 0:
                    {
                        Mentor m = new Mentor()
                        {
                            DisplayName = txb_MentorName.Text.Trim(),
                            Id = Guid.NewGuid()
                        };
                        Program.UserViewModelLocator.AllMentors.Add(m);
                    }
                    break;
                case 1:
                    {
                        Graduate g = new Graduate() 
                        {
                         Id=Guid.NewGuid(),
                         DisplayName=txb_GraduateName.Text.Trim(),
                         MentorId = (Guid)combx_Mentor.SelectedValue,
                        };
                        Program.UserViewModelLocator.AllGraduates.Add(g);
                    }
                    break;
            }
            //MessageBox.Show("添加成功！");
            this.Close();
        }

        private void txb_MentorName_TextChanged(object sender, EventArgs e) {
            //Regex.IsMatch(txb_MentorName.Text.Trim(),"[\u4e00-\u9fa5]"
        }

        private void UserAddFrom_Load(object sender, EventArgs e) {
            if (StartMode == Mode.Student) 
            {
                //tab_AddUser.TabPages[1].Select();
                tab_AddUser.SelectedTab = tab_AddUser.TabPages[1];
            }
        }
    }

    public enum Mode 
    {
        Mentor,
        Student
    }
}
